//
//  JKJShopInfoTabViewCell.m
//  jiukeji
//
//  Created by 小宇 on 2017/11/23.
//  Copyright © 2017年 小宇. All rights reserved.
//

#import "JKJShopInfoTabViewCell.h"
@interface JKJShopInfoTabViewCell()
@property (nonatomic,strong) UILabel *titleLab;
@property (nonatomic,strong) UILabel *fulab;
@property (nonatomic,strong) UILabel *moneyLab;
@property (nonatomic,strong) UILabel *jiekuanqixian;
@property (nonatomic,strong) UILabel *jiekuantime;
@property (nonatomic,strong) UIImageView *iconView;
@end

@implementation JKJShopInfoTabViewCell
-(void)setupUI{
	//self.backgroundColor = [UIColor whiteColor];
	UILabel *titleLab = [UILabel cx_textLabel:@"宋江白卡" fontSize:15 Color:0];
	[self addSubview:titleLab];
	_titleLab = titleLab;
	[titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
		make.left.equalTo(self).offset(15);
		make.top.equalTo(self).offset(10);
	}];

	UIImageView *iconView = [[UIImageView alloc] init];
	iconView.image = [UIImage imageNamed:@"hot"];
	_iconView = iconView;
	[self addSubview:iconView];
	[iconView mas_makeConstraints:^(MASConstraintMaker *make) {
		make.left.equalTo(titleLab.mas_right).offset(12.5);
		make.centerY.equalTo(titleLab);
	}];

	UILabel *fulab = [UILabel cx_textLabel:@"首借全免 拒就送钱" fontSize:12 Color:0];
	_fulab = fulab;
	fulab.textColor = [UIColor hm_colorWithR:0 G:0 B:0 alpha:0.3];
	[self addSubview:fulab];
	[fulab mas_makeConstraints:^(MASConstraintMaker *make) {
		make.top.equalTo(titleLab.mas_bottom).offset(5);
		make.left.equalTo(titleLab);
	}];

	UIView *hengView = [[UIView alloc] init];
	[self addSubview:hengView];
	hengView.backgroundColor = [UIColor hm_colorWithHex:0xe5e5e5];
	[hengView mas_makeConstraints:^(MASConstraintMaker *make) {
		make.top.equalTo(fulab.mas_bottom).offset(10);
		make.left.right.equalTo(self);
		make.height.equalTo(@(0.5));
	}];

	UIButton *jieqianBtn = [[UIButton alloc] init];
	[self addSubview:jieqianBtn];
	jieqianBtn.titleLabel.font = [UIFont systemFontOfSize:12];
	jieqianBtn.backgroundColor = [UIColor hm_colorWithHex:0xff5a57];
	[jieqianBtn setTitle:@"立即借款" forState:UIControlStateNormal];
	jieqianBtn.layer.cornerRadius = 3.0;
	jieqianBtn.layer.masksToBounds = YES;
	[jieqianBtn mas_makeConstraints:^(MASConstraintMaker *make) {
		make.top.equalTo(titleLab);
		make.bottom.equalTo(fulab);
		make.width.equalTo(@(70));
		make.right.equalTo(self).offset(-16);
	}];

	UILabel *moneyLab = [UILabel cx_textLabel:@"1000-5000" fontSize:16 Color:0xff5a57];
	_moneyLab = moneyLab;
	[self addSubview:moneyLab];

	float f = self.frame.size.width * 0.125;
	moneyLab.text = @"1000-5000";
	moneyLab.textAlignment = NSTextAlignmentCenter;
	[moneyLab mas_makeConstraints:^(MASConstraintMaker *make) {
		make.top.equalTo(hengView).offset(15);
		make.left.equalTo(self).offset(f);
	}];

	
	UILabel *nameLabe = [UILabel cx_textLabel:@"借款额度" fontSize:12 Color:0];
	[self addSubview:nameLabe];
	nameLabe.textColor = [UIColor hm_colorWithR:0 G:0 B:0 alpha:0.3];
	[nameLabe mas_makeConstraints:^(MASConstraintMaker *make) {
		make.top.equalTo(moneyLab.mas_bottom).offset(5);
		make.centerX.equalTo(moneyLab);
	}];

	UIView *lineView = [[UIView alloc] init];
	[self addSubview:lineView];
	lineView.backgroundColor = [UIColor hm_colorWithHex:0xe6e6e6];
	[lineView mas_makeConstraints:^(MASConstraintMaker *make) {
		make.top.equalTo(hengView).offset(15);
		make.centerX.equalTo(hengView);
		make.height.equalTo(@(40));
		make.width.equalTo(@(1));
	}];

	UIView *garyView = [[UIView alloc] init];
	garyView.backgroundColor = [UIColor hm_colorWithHex:0xf8f8f8];
	[self addSubview:garyView];
	[garyView mas_makeConstraints:^(MASConstraintMaker *make) {
		make.bottom.equalTo(self.mas_bottom).offset(-8);
		make.height.equalTo(@(8));
		make.left.right.equalTo(self);
	}];

	UILabel *jiekuanqixian = [UILabel cx_textLabel:@"借款期限 7-21天" fontSize:12 Color:0];
	_jiekuanqixian = jiekuanqixian;
	[self addSubview:jiekuanqixian];


	NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:jiekuanqixian.text];
	[str addAttribute:NSForegroundColorAttributeName value:[UIColor hm_colorWithHex:0xf3f3f3] range:NSMakeRange(0,0)];
	[str addAttribute:NSForegroundColorAttributeName value:[UIColor hm_colorWithHex:0xcccccc] range:NSMakeRange(0,4)];

	jiekuanqixian.attributedText = str;

	[jiekuanqixian mas_makeConstraints:^(MASConstraintMaker *make) {
		make.centerY.equalTo(moneyLab);
		make.left.equalTo(lineView).offset(f);
	}];

	UILabel *jiekuantime = [UILabel cx_textLabel:@"放款时间 2小时" fontSize:12 Color:0];
	_jiekuantime = jiekuantime;
	[self addSubview:jiekuantime];
	NSMutableAttributedString *str1 = [[NSMutableAttributedString alloc] initWithString:jiekuantime.text];
	[str1 addAttribute:NSForegroundColorAttributeName value:[UIColor hm_colorWithHex:0xf3f3f3] range:NSMakeRange(0,0)];
	[str1 addAttribute:NSForegroundColorAttributeName value:[UIColor hm_colorWithHex:0xcccccc] range:NSMakeRange(0,4)];
	jiekuantime.attributedText = str1;

	[jiekuantime mas_makeConstraints:^(MASConstraintMaker *make) {
		make.left.equalTo(jiekuanqixian);
		make.top.equalTo(jiekuanqixian.mas_bottom).offset(5);
	}];
	//UILabel *time = [[UILabel alloc] init];
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
	if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier])
	{
		[self setupUI];
	}
	return self;
}


-(void)setModel:(JKJRecommendModel *)model{
	_model = model;
	_titleLab.text = model.name;
	_fulab.text = model.Description;
	_moneyLab.text = [NSString stringWithFormat:@"%ld-%ld",model.min_loan,model.max_loan];
	_jiekuanqixian.text = [NSString stringWithFormat:@"借款期限 %@",model.duration_desc];

   NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:_jiekuanqixian.text];
   [str addAttribute:NSForegroundColorAttributeName value:[UIColor hm_colorWithHex:0xf3f3f3] range:NSMakeRange(0,0)];
   [str addAttribute:NSForegroundColorAttributeName value:[UIColor hm_colorWithHex:0xcccccc] range:NSMakeRange(0,4)];

   _jiekuanqixian.attributedText = str;

	_jiekuantime.text = [NSString stringWithFormat:@"借款时间 %@",model.loan_speed];

	NSMutableAttributedString *str1 = [[NSMutableAttributedString alloc] initWithString:_jiekuantime.text];
	[str1 addAttribute:NSForegroundColorAttributeName value:[UIColor hm_colorWithHex:0xf3f3f3] range:NSMakeRange(0,0)];
	[str1 addAttribute:NSForegroundColorAttributeName value:[UIColor hm_colorWithHex:0xcccccc] range:NSMakeRange(0,4)];
	_jiekuantime.attributedText = str1;

	if([model.label isEqualToString:@"new"]){
		_iconView.image = [UIImage imageNamed:@"new"];
	}else if([model.label isEqualToString:@"hot"]){
		_iconView.image = [UIImage imageNamed:@"hot"];
	}
	
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
